package jjn.round1;

/**
 * @author Jjn
 * @since 2022/8/15 23:28
 */
public class LeetCode125_ValidPalindrome {

    public boolean isPalindrome(String s) {
        int left = 0, right = s.length() - 1;
        while (left < right) {
            while (!Character.isLetterOrDigit(s.charAt(left)) && left < right) {
                ++left;
            }
            while (!Character.isLetterOrDigit(s.charAt(right)) && left < right) {
                --right;
            }
            if (left < right) {
                if (Character.toLowerCase(s.charAt(left)) != Character.toLowerCase(s.charAt(right))) {
                    return false;
                }
                ++left;
                --right;
            }
        }

        return true;
    }

}
